// pages/demo/demo.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    
    },
    /**
   * 检查授权
   */











  checkWerunAuthorize:function(){
    let that = this;
    //检测
  wx.login({
    complete: (res) => {},
    success(res){
      console.log(res)
      const js_code=res.code;
    wx.getSetting({
      success(res) { 
        console.log(res)
        if (!res.authSetting['scope.werun']) {
          wx.authorize({
            scope: 'scope.werun',
            //允许
            success(res) {
              // that.getWeRunData();
              console.log(res)
              that.getWeRunData({
                success(res){
                  const encryptedData=res.encryptedData
                  const iv=res.iv
                  var runObj={
                    encryptedData:encryptedData,
                    iv:iv,
                    js_code:js_code
                  }
                }
              });
            },
            //拒绝
            fail: res => {
                wx.showModal({
                  title: '提示',
                  content: '需要您授权获取您的微信步数',
                  showCancel: false,
                  success: modalSuccess => {
                    //打开设置
                    wx.openSetting({
                      success(settingdata) {

                        if (settingdata.authSetting['scope.werun']) {
                          wx.showModal({
                            title: '提示',
                            content: '获取权限成功,再次点击获取',
                            showCancel: false,
                          })
                        } else {
                          wx.showModal({
                            title: '提示',
                            content: '获取权限失败，将无法获取您的微信步数',
                            showCancel: false,
                          })
                        }
                      },
                      fail(failData) {

                      },
                      complete(finishData) {
                        
                        that.getWeRunData();
                      }
                    })
                  }
                })

            }


          })
          
        }else{



          console.log("不用再出弹窗了")

          //从本次获取参数

          return;
       
        }

      }
    })
  }
  });
}
  ,

  getWeRunData(){
    wx.getWeRunData({
      complete: (res) => {
         console.log(res);
      },
    })
    console.log("用户执行了获取步数");
  },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})